package com.systop.mapper;

import com.systop.pojo.Identification;
import com.systop.pojo.School_data;
import com.systop.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    //用户登陆
    @Select("select * from user where user_name=#{user_name} and user_password=#{user_password}")
    User login(String user_name,String user_password);
    //用户注册
    @Insert("insert into user (user_name,user_password,user_sex,user_phone,user_address,user_photo,user_status,remark)values(#{user_name},#{user_password},#{user_sex},#{user_phone},#{user_address},#{user_photo},#{user_status},#{remark})")
    Integer addUser(User user);
    //根据id查询用户
    @Select("select * from user where user_id=#{user_id}")
    User selUserByid(Integer user_id);
    //用户修改信息
    @Update("<script>"+
            "update user set"+
            "<if test=\"user_name != null\">user_name=#{user_name},</if>"+
            "<if test=\"user_password != null\">user_password=#{user_password},</if>"+
            "<if test=\"user_sex != null\">user_sex=#{user_sex},</if>"+
            "<if test=\"user_phone != null\">user_phone=#{user_phone},</if>"+
            "<if test=\"user_address != null\">user_address=#{user_address},</if>"+
            "<if test=\"user_photo != null\">user_photo=#{user_photo},</if>"+
            "<if test=\"user_status != null\">user_status=#{user_status},</if>"+
            "<if test=\"remark != null\">remark=#{remark}</if>"+
            "where user_id = #{user_id}" +
            "</script>")
    Integer updUser(User user);
    //用户认证（从学校数据里查找是否有这个人的信息）
    @Select("select * from school_data where school_data_name=#{school_data_name} and school_data_num=#{school_data_num} and school_data_college=#{school_data_college}")
    School_data selUs(String school_data_name,String school_data_num,String school_data_college);
    //用户认证（把信息填到认证表）
    @Insert("insert into identification (identification_user_id,identification_student_name,identification_student_num,identification_school_name,remark)values(#{identification_user_id},#{identification_student_name},#{identification_student_num},#{identification_school_name},#{remark})")
    Integer addIdent(Identification identification);
    //查找数据库此用户名是否存在
    @Select("select * from user where user_name=#{user_name}")
    User selUseName(String user_name);
}
